home *** CD-ROM | disk | FTP | other *** search
- unit fmMain;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Save: TButton;
- Restore: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure SaveClick(Sender: TObject);
- procedure RestoreClick(Sender: TObject);
- private
- { Private declarations }
- hDIPSLib: hModule;
- hDeskWin: hWnd;
- function SetDIPSHook (ThreadID: DWord): Boolean;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses CommCtrl;
-
- // Get a window to the ListView control which implements the desktop
-
- function GetDesktopListView: HWnd;
- var
- buff: array [0..255] of Char;
- begin
- Result := GetWindow (GetWindow (FindWindow ('ProgMan', Nil),
- gw_Child), gw_Child);
-
- if Result <> 0 then begin
- GetClassName (Result, buff, sizeof (buff));
- if buff <> 'SysListView32' then Result := 0;
- end;
-
- if Result = 0 then raise Exception.Create ('Desktop ListView control not found');
- end;
-
- function GetDesktopThread: DWord;
- begin
- Result := GetWindowThreadProcessID (GetDesktopListView, Nil);
- end;
-
- function TForm1.SetDIPSHook (ThreadID: DWord): Boolean;
- type
- SetDIPSHook = function (ThreadID: DWord): Bool; stdcall;
- var
- proc: SetDIPSHook;
- begin
- Result := False;
- proc := GetProcAddress (hDIPSLib, '_SetDIPSHook@4');
- if @proc <> Nil then Result := proc (ThreadID);
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- Msg: TMsg;
- begin
- hDIPSLib := LoadLibrary ('DIPSLIB.DLL');
- if hDIPSLib = 0 then raise Exception.Create ('Can''t find DLL!');
- SetDIPSHook (GetDesktopThread);
- GetMessage (Msg, 0, 0, 0);
- hDeskWin := FindWindow (Nil, 'Delphi Desktop 2001');
- if hDeskWin = 0 then raise Exception.Create ('Trouble at ''mill');
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- SendMessage (hDeskWin, wm_Close, 0, 0);
- while IsWindow (hDeskWin) do Application.ProcessMessages;
- SetDIPSHook (0);
- FreeLibrary (hDIPSLib);
- end;
-
- procedure TForm1.SaveClick(Sender: TObject);
- begin
- SendMessage (hDeskWin, wm_App, GetDesktopListView, 1);
- end;
-
- procedure TForm1.RestoreClick(Sender: TObject);
- begin
- SendMessage (hDeskWin, wm_App, GetDesktopListView, 0);
- end;
-
- end.
-